<?php

if (!defined('PHOX') or !constant('PHOX')) die('Direct access not allowed!');

/**
 * Cookie 
 * 
 * @package lib
 * @version 0.1
 * @author Pedro Eugénio <voxmachina@sapo.pt> 
 * @license GPL v.3
 */
class Cookie 
{

  private $time;
  private $path;
  private $domain;
    
 /**
  * __construct 
  * 
  * @access protected
  * @return void
  */
  function __construct()
  {
    $this->time    = time() + (7 * 24 * 60 * 60);
    $this->path    = COOKIE_PATH;
    $this->domain  = COOKIE_DOMAIN;
  }
    
 /**
  * set 
  * 
  * @param mixed $key 
  * @param mixed $val 
  * @access public
  * @return void
  */
  function set( $key , $val )
  {
    setcookie( $key , $val , $this->time , $this->path , $this->domain , false , true );
  }
    
 /**
  * _unset 
  * 
  * @access protected
  * @return void
  */
  function _unset() 
  {   
    $_COOKIE = array();
  }
    
 /**
  * get 
  * 
  * @param mixed $key 
  * @access public
  * @return cookie value
  */
  function get( $key )
  {  
    if( !empty( $_COOKIE[ $key ] ) ) 
    {
      return $_COOKIE[ $key ];
    } else {
      return false;
    }
  }
    
 /**
  * setData 
  * 
  * @param array $data 
  * @access public
  * @return void
  */
  function setData( $data = array() )
  {
    if( is_array( $data ) )
    {
      foreach( $data as $key => $val )
      {
        $_COOKIE[$key] = $val;
      }
    }
  }
  
}
 
?>
